package pedongi.mobile.colorfinder.knowledgebase;

import android.content.SharedPreferences;

public class KnowledgeBaseDriver {
	private static KnowledgeBaseDriver instance = null;
	
	private final static int MAX_SET = 72;
	private final static String UNDEFINED_VALUE = "UNDEFINED VALUE";
	
	private SharedPreferences pref = null;
	
	private KnowledgeBaseDriver() {
	}
	
	public void setPref(SharedPreferences pref) {
		this.pref = pref;
	}
	
	public static KnowledgeBaseDriver getInstance() {
		if (instance == null)
			instance = new KnowledgeBaseDriver();
		
		return instance;
	}
	
	public TrainingData getTrainingData(int index) {
		if (pref == null)
			return null;
		
		if (index <= MAX_SET) {
			String value = pref.getString(String.valueOf(index), UNDEFINED_VALUE);
			
			if (value.equals(UNDEFINED_VALUE))
				return null;
			else
				return TrainingData.createFromString(value);
		}
		
		return null;
	}
	
	public String getTrainingDataD(int index) {
		if (pref == null)
			return null;
		
		if (index <= MAX_SET) {
			return pref.getString(String.valueOf(index), "UNDEFINED");
		}
		
		return null;
	}
}
